{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2\n",
    "\n",
    "import sys \n",
    "from os import getcwd, path\n",
    "sys.path.append(path.dirname(getcwd()))\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sb\n",
    "import pandas as pd\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from utils.paper import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{{{cohorts_version:0.4.0}}}\n"
     ]
    }
   ],
   "source": [
    "import cohorts\n",
    "hyper_label_printer(formatter=None, label=\"cohorts_version\", value=cohorts.__version__.split(\"+\")[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{{{topiary_version:0.1.0}}}\n"
     ]
    }
   ],
   "source": [
    "import topiary\n",
    "hyper_label_printer(formatter=None, label=\"topiary_version\", value=topiary.__version__)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{{{varcode_version:0.5.10}}}\n"
     ]
    }
   ],
   "source": [
    "import varcode\n",
    "hyper_label_printer(formatter=None, label=\"varcode_version\", value=varcode.__version__.split(\"+\")[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{{{pyensembl_version:1.0.3}}}\n"
     ]
    }
   ],
   "source": [
    "import pyensembl\n",
    "hyper_label_printer(formatter=None, label=\"pyensembl_version\", value=pyensembl.__version__)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{{{isovar_version:0.0.6}}}\n"
     ]
    }
   ],
   "source": [
    "import isovar\n",
    "hyper_label_printer(formatter=None, label=\"isovar_version\", value=isovar.__version__)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{{{scipy_version:0.18.1}}}\n"
     ]
    }
   ],
   "source": [
    "import scipy\n",
    "hyper_label_printer(formatter=None, label=\"scipy_version\", value=scipy.__version__)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{{{lifelines_version:0.9.1.0}}}\n"
     ]
    }
   ],
   "source": [
    "import lifelines\n",
    "hyper_label_printer(formatter=None, label=\"lifelines_version\", value=lifelines.__version__)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{{{polyphen_version:2.2.2}}}\n"
     ]
    }
   ],
   "source": [
    "from utils import data\n",
    "polyphen_version = data.POLYPHEN_DATA_DUMP.split(\"polyphen-\")[1].split(\"-whess\")[0]\n",
    "hyper_label_printer(formatter=None, label=\"polyphen_version\", value=polyphen_version)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{{{pystan_version:2.12.0.0}}}\n"
     ]
    }
   ],
   "source": [
    "import pystan\n",
    "hyper_label_printer(formatter=None, label=\"pystan_version\", value=pystan.__version__)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import os\n",
    "r_lib_path = os.path.join(os.path.dirname(getcwd()),'Ranalyses','.R_env')\n",
    "if not os.path.exists(r_lib_path):\n",
    "    print(\"R lib path doesn't exist. Creating it.\")\n",
    "    os.mkdir(r_lib_path)\n",
    "assert(os.path.exists(r_lib_path))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import rpy2\n",
    "from rpy2 import robjects as ro\n",
    "from rpy2.robjects import pandas2ri\n",
    "pandas2ri.activate()\n",
    "R = ro.r\n",
    "%load_ext rpy2.ipython\n",
    "ro.globalenv['r_lib_path'] = r_lib_path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%%R\n",
    ".libPaths(new = r_lib_path)\n",
    "suppressWarnings(suppressPackageStartupMessages({\n",
    "options(repos = c(CRAN = 'https://cran.rstudio.com'))\n",
    "if (!require('survival', lib.loc = r_lib_path))\n",
    "    install.packages('survival', lib = r_lib_path)\n",
    "if (!require('dplyr', lib.loc = r_lib_path))\n",
    "    install.packages('dplyr', lib = r_lib_path)\n",
    "\n",
    "library('survival', lib.loc = r_lib_path)\n",
    "library('dplyr', lib.loc = r_lib_path)\n",
    "}))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1] \"{{{r_survival_version:2.39.5}}}\"\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%%R\n",
    "print(paste('{{{r_survival_version:', packageVersion('survival', lib.loc=r_lib_path), '}}}', sep = ''))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1] \"{{{r_version:3.3.1}}}\"\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%%R\n",
    "print(paste('{{{r_version:', getRversion(), '}}}', sep = ''))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
